j3deditor.bin.util
Class XMLParser

java.lang.Object
  extended by j3deditor.bin.util.XMLParser

public class XMLParser
extends java.lang.Object

Tool for loading and saving XML files.

Author:
Risto Seene

Constructor Summary
XMLParser()
          Creates an instance of XMLParser.
XMLParser(java.io.File file)
          Creates an instance of XMLParser and loads an XML file if possible.
XMLParser(java.io.InputStream resource)
          Creates an instance of XMLParser and loads an XML file if possible.
 
Method Summary
 org.w3c.dom.Node getAttribute(java.lang.String attribute, org.w3c.dom.Node node)
          Returns the requested attribute of the given node.
 org.w3c.dom.Node getRoot()
          Returns the root element of the document tree.
 java.lang.String getRootAttribute(java.lang.String attribute)
          Returns the requested attribute of the root node.
 java.lang.String[][] getTable()
          Returns 2-dimensional array that contains the elements of the document tree.
 java.lang.String[][] getTable(java.lang.String node, java.lang.String[] elements)
          Returns 2-dimensional array that contains the specified descendants of the element named node.
 void saveFile(java.io.File file)
          Saves the document tree to specified file.
 void setData(java.lang.String[][] data)
          Creates the document tree from 2-dimensional array[m][n] where n equals 2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParser

public XMLParser()
Creates an instance of XMLParser.


XMLParser

public XMLParser(java.io.InputStream resource)
          throws java.lang.Exception
Creates an instance of XMLParser and loads an XML file if possible.

Parameters:
resource - stream of the XML file that will be loaded
Throws:
java.lang.Exception - if cannot load specified file

XMLParser

public XMLParser(java.io.File file)
          throws java.lang.Exception
Creates an instance of XMLParser and loads an XML file if possible.

Parameters:
file - XML file that will be loaded
Throws:
java.lang.Exception - if cannot load specified file
Method Detail

getRoot

public org.w3c.dom.Node getRoot()
Returns the root element of the document tree.

Returns:
Returns the root element of the document tree

getRootAttribute

public java.lang.String getRootAttribute(java.lang.String attribute)
Returns the requested attribute of the root node.

Parameters:
attribute - the name of the attribute
Returns:
Returns the requested attribute of the root node

getAttribute

public org.w3c.dom.Node getAttribute(java.lang.String attribute,
                                     org.w3c.dom.Node node)
                              throws java.lang.Exception
Returns the requested attribute of the given node.

Parameters:
attribute - the name of the attribute
node - node which attribute is requested
Returns:
Returns the given attribute of the given node
Throws:
java.lang.Exception - if unable to aquire the requested attribute

getTable

public java.lang.String[][] getTable()
                              throws java.lang.Exception
Returns 2-dimensional array that contains the elements of the document tree.

Returns:
Returns 2-dimensional String array that contains the elements of the document tree
Throws:
java.lang.Exception - if something bad happens

getTable

public java.lang.String[][] getTable(java.lang.String node,
                                     java.lang.String[] elements)
                              throws java.lang.Exception
Returns 2-dimensional array that contains the specified descendants of the element named node.

Parameters:
node - name of the node which descendants are required
elements - array of node names which are required
Returns:
Returns 2-dimensional String array that contains the elements of the document tree
Throws:
java.lang.Exception - if something bad happens

setData

public void setData(java.lang.String[][] data)
             throws java.lang.Exception
Creates the document tree from 2-dimensional array[m][n] where n equals 2.

Parameters:
data - 2-dimensional String array
Throws:
java.lang.Exception - ArrayOutOfBoundsException if data has less than 2 columns

saveFile

public void saveFile(java.io.File file)
Saves the document tree to specified file.

Parameters:
file - name of the file